/*
 * Date         Author     Note
 * 2014.11.24   wzwz       工作参数窗口
 * 2015.04.28   wzwz       增加二段度目等参数
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <minigui/common.h>
#include <minigui/minigui.h>
#include <minigui/gdi.h>
#include <minigui/window.h>
#include <minigui/control.h>
#include "resource.h"
#include "func.h"
#include "lang.h"
#include "work.h"
#include "com.h"
#include "mhlabel.h"
#include "keypane.h"
#include "mh/common.h"
#include "run.h"
#include "info.h"

#define START_POINT_CAPTION_WIDTH       250
#define START_POINT_CAPTION_HEIGHT      24
#define START_POINT_NAME_WIDTH          60
#define START_POINT_CAPTION_LEFT        (CX_EDGE_LEFT * 2)
#define START_POINT_CAPTION_TOP         (CY_TITLE4_HEIGHT + CX_EDGE_LEFT * 2 - 16)
#define START_POINT_INTER               4
/*
 *
 */
static void CreateMacParamInterface(HWND hWnd)
{
    char sc[256] = {0};
       CreateWindow (MH_STATIC_NAME,
        "",
        WS_CHILD | WS_VISIBLE,
        ID_ESC,
        CX_XTCS_WND_BMP - CX_ASK_BMP * 2,
        10,
        CX_ASK_BMP,
        CY_ASK_BMP,
        hWnd, (int)&g_bmp[BMP_FALSE]);
    //left
    CreateWindow (MH_LABEL_NAME,
        MW_DUMU1_TO_MAC_LEFT_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetDumu1ToMacLeftLen(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_DUMU2_TO_MAC_LEFT_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 1,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetDumu2ToMacLeft(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 1,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_DUMU3_TO_MAC_LEFT_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 2,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    //sprintf(sc, "%u", GetMacResetSpeed(g_knit_data));
    sprintf(sc, "%u", GetDumu3ToMacLeftLen(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 2,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_DUMU4_TO_MAC_LEFT_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 3,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetDumu4ToMacLeft(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 3,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_MAC_WIDTH,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 4,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetMacWidth(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_MAC_WIDTH,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 4,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_SELECT5_TO_MAC_RIGHT_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 5,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetSelect5ToMacRightLen(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 5,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_SELECT6_TO_MAC_RIGHT_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 6,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%d", GetSelect6ToMacRightLen(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 6,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_FUEL_TIME,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 7,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetFuelTime(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_FUEL_TIME,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 7,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_FUEL_GAB,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 8,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetFuelGab(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_FUEL_GAB,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 8,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_ROCK_MODE,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 9,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%d", GetRockMode(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_ROCK_MODE,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 9,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);
    //mid
    CreateWindow (MH_LABEL_NAME,
        MW_ROCK_ZERO_DIR,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 10,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%d", GetRockZeroDir(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_ROCK_ZERO_DIR,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 10,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);
    CreateWindow (MH_LABEL_NAME,
        MW_RED_LIGHT_TIME,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 11,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetRedLightTime(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_RED_LIGHT_TIME,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 11,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);
    CreateWindow (MH_LABEL_NAME,
        MW_SEVER_TYPE,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 12,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetSeverType(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_SEVER_TYPE,
        START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 12,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    CreateWindow (MH_LABEL_NAME,
        MW_SINK_DIR,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetSinkDir(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_SINK_DIR,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);
    CreateWindow (MH_LABEL_NAME,
        MW_YARN_TYPE,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 1,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetYarnType(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_YARN_TYPE,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 1,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_NULL_DATA,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 2,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    CreateWindow (MH_EDIT_NAME,
        "0",
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_NULL_DATA,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 2,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    CreateWindow (MH_LABEL_NAME,
        MW_MAC_SINK1_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 3,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetSink1ToMacLeftLen(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_MAC_PARAM_SINK1,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 3,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);
    CreateWindow (MH_LABEL_NAME,
        MW_MAC_SINK2_LEN,
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_STATIC,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 4,
        START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, MH_LABEL_COLOR_1GROUP);
    sprintf(sc, "%u", GetSink2ToMacLeftLen(g_knit_data));
    CreateWindow (MH_EDIT_NAME,
        sc,
        WS_CHILD | WS_VISIBLE,
        IDC_EDIT_MAC_PARAM_SINK2,
        CX_SCREEN / 2 + START_POINT_CAPTION_LEFT + START_POINT_CAPTION_WIDTH,
        START_POINT_CAPTION_TOP + (START_POINT_CAPTION_HEIGHT + START_POINT_INTER) * 4,
        START_POINT_NAME_WIDTH,
        START_POINT_CAPTION_HEIGHT,
        hWnd, 0);

    //tip
    CreateWindow(MH_LABEL_NAME,
        GetString(847),
        WS_CHILD | WS_VISIBLE | BS_LEFT,
        IDC_TIP,
        150,
        CY_XTCS_WND_BMP - 35,
        600,
        20,
        hWnd, MH_LABEL_BKGND_2GREEN | MH_LABEL_TEXT_YELLOW);
}
/*
 *把界面内有变更的数据传给g_knit_data
 */
static void OnSetKnitValue(HWND hWnd, int nID)
{
    WND_EXTRA_DATA data;
    data.value = GetWindowAdditionalData(hWnd);
    data.mac_param.change = TRUE;
    const char *sc = GetWindowCaption(GetDlgItem(hWnd, nID));
    switch(nID)
    {

    case IDC_EDIT_YARN_TYPE:
        {
            uchar n = atoi(sc);
            SetYarnType(g_knit_data, n);
        }
        break;
    case IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN:
        {
            uchar n = atoi(sc);
            SetDumu1ToMacLeftLen(g_knit_data, n);
        }
        break;
    case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
        {
            int n = atoi(sc);
            SetDumu3ToMacLeftLen(g_knit_data, n);
        }
        break;
    case IDC_EDIT_FUEL_GAB:
        {
            int n = atoi(sc);
            SetFuelGab(g_knit_data, n);
        }
        break;
    case IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN:
        {
            ushort n = atoi(sc);
            SetSelect5ToMacRightLen(g_knit_data, n);
        }
        break;
    case IDC_EDIT_MAC_WIDTH:
        {
            uchar n = atoi(sc);
            SetMacWidth(g_knit_data, n);
        }
        break;
    case IDC_EDIT_ROCK_MODE:
        {
            uchar n = atoi(sc);
            SetRockMode(g_knit_data, n);
        }
        break;
    case IDC_EDIT_ROCK_ZERO_DIR:
        {
            uchar n = atoi(sc);
            SetRockZeroDir(g_knit_data, n);
        }
        break;
    case IDC_EDIT_RED_LIGHT_TIME:
        {
            uchar n = atoi(sc);
            SetRedLightTime(g_knit_data, n);
        }
        break;
    case IDC_EDIT_SEVER_TYPE:
        {
            uchar n = atoi(sc);
            SetSeverType(g_knit_data, n);
        }
        break;
    case IDC_EDIT_SINK_DIR:
        {
            uint n = atoi(sc);
            SetSinkDir(g_knit_data, n);
        }
        break;
    case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
        {
            uint n = atoi(sc);
            SetDumu2ToMacLeft(g_knit_data, n);
        }
        break;
    case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
        {
            uchar n = atoi(sc);
            SetDumu4ToMacLeft(g_knit_data, n);
        }
        break;
    case IDC_EDIT_FUEL_TIME:
        {
            char n = atoi(sc);
            SetFuelTime(g_knit_data, n);
        }
        break;
    case IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN:
        {
            uchar n = atoi(sc);
            SetSelect6ToMacRightLen(g_knit_data, n);
        }
        break;
    case IDC_EDIT_MAC_PARAM_SINK1:
        {
            short n = atoi(sc);
            SetSink1ToMacLeftLen(g_knit_data, n);
        }
        break;
    case IDC_EDIT_MAC_PARAM_SINK2:
        {
            short n =atoi(sc);
            SetSink2ToMacLeftLen(g_knit_data, n);
        }
        break;
    }
    SetWindowAdditionalData(hWnd, data.value);
}
/*
 *设置好控件对象值的范围和对象区域作为参数给创建键盘对象
 */
static void OnCreateKeyboard(HWND hWnd, ushort nID)
{
    int index = 0;
    switch(nID)
    {
    case IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN:
        index = 0;
        break;
    case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
        index = 1;
        break;
    case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
        index = 2;
        break;
    case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
        index = 3;
        break;
    case IDC_EDIT_MAC_WIDTH:
        index = 4;
        break;
    case IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN:
        index = 5;
        break;
    case IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN:
        index = 6;
        break;
    case IDC_EDIT_FUEL_TIME:
        index = 7;
        break;
    case IDC_EDIT_FUEL_GAB:
        index = 8;
        break;
    case IDC_EDIT_ROCK_MODE:
        index = 9;
        break;
    case IDC_EDIT_ROCK_ZERO_DIR:
        index = 10;
        break;
    case IDC_EDIT_RED_LIGHT_TIME:
        index = 11;
        break;
    case IDC_EDIT_SEVER_TYPE:
        index = 12;
        break;
    case IDC_EDIT_SINK_DIR:
        index = 13;
        break;
    case IDC_EDIT_YARN_TYPE:
        index = 14;
        break;
    }
    int area[15][2] = { { 0, 1000 }, { 0, 1000 }, { 0, 1000 }, { 0, 1000 },
                                        { -9999999, 9999999 },{ -9999999,9999999 }, { -9999999, 9999999 }, { -9999999, 9999999 },
                                        { -9999999, 9999999 }, { 0, 4 }, { 0, 1 }, { 0, 60 }, { 0, 1 }, { 0, 1 },
                                        { 0, 1 }};
    HWND hTmp = GetDlgItem(hWnd, nID);
    RECT rect;
    GetClientRect(hTmp, &rect);
    ClientToScreen(hTmp, &rect.left, &rect.top);

    ClientToScreen(hTmp, &rect.right, &rect.bottom);
    int value = atoi(GetWindowCaption(hTmp));
    CreateKeyboardWindow(hWnd, rect, area[index][0], area[index][1], value);
}

/*
 *界面下方的警告提醒
 */
static void OnChangeCtrl(HWND hWnd)
{
    HWND hTmp = GetFocusChild(hWnd);
    ushort nID = GetDlgCtrlID(hTmp);
    const char *sc = "";
    switch (nID)
    {
    case IDC_EDIT_SELECT1_TO_MAC_LEFT_LEN:
    case IDC_EDIT_SELECT2_TO_MAC_LEFT_LEN:
    case IDC_EDIT_SELECT3_TO_MAC_LEFT_LEN:
    case IDC_EDIT_SELECT4_TO_MAC_LEFT_LEN:
        sc = GetString(847);
        break;
    case IDC_EDIT_SELECT_PIECE:
        sc = GetString(848);
        break;
    case IDC_EDIT_SELECT_SECT_MAC:
        sc = GetString(849);
        break;
    case IDC_EDIT_PROBE_TO_MAC_LEFT_LEN:
        sc = GetString(850);
        break;
    case IDC_EDIT_YARN_TYPE:
        sc = GetString(851);
        break;
    case IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN:
        sc = GetString(847);
        break;
    case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
        sc = GetString(847);
        break;
    case IDC_EDIT_ROCK_MODE:
        sc = GetString(853);
        break;
    case IDC_EDIT_ROCK_ZERO_DIR:
        sc = GetString(854);
        break;
    case IDC_EDIT_LANGUAGE_MAC:
        sc = GetString(855);
        break;
    case IDC_EDIT_RED_LIGHT_TIME:
        sc = GetString(856);
        break;
    case IDC_EDIT_SEVER_TYPE:
        sc = GetString(857);
        break;
    case IDC_EDIT_SELECT_START:
        sc = GetString(858);
        break;
    case IDC_EDIT_SINK_DIR:
        sc = GetString(859);
        break;
    case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
        sc = GetString(847);
        break;
    case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
        sc = GetString(847);
        break;
    }
    hTmp = GetDlgItem(hWnd, IDC_TIP);
    SetWindowCaption(hTmp, sc);
    InvalidateRect(hTmp, NULL, TRUE);
}
/*
 *
 */
static void OnBtnCmd(HWND hWnd, int nID)
{
    WND_EXTRA_DATA data;
    data.value = GetWindowAdditionalData(hWnd);
	switch(nID)
	{
	case ID_ESC:
	    {
	        if(data.mac_param.change)
            {
                int ret = WriteMacFile(MAC_PARAM_FILE, g_knit_data);
                if(ret)
                {
                    printf("write param: %d\n", ret);
                    AfxInfoBox(hWnd, NULL, GetString(481));
                }
                else
                {
                    MH_FILE_SYNC();
                }
            }
            SendPartsParam(g_knit_data);
            data.mac_param.change = FALSE;
	    	PostMessage (hWnd, MSG_CLOSE, 0, 0);
	    }
		break;
    case IDC_EDIT_YARN_TYPE:
    case IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN:;
    case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
    case IDC_EDIT_FUEL_GAB:
    case IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN:
    case IDC_EDIT_MAC_WIDTH:
    case IDC_EDIT_SELECT_MODE:
    case IDC_EDIT_ROCK_MODE:
    case IDC_EDIT_ROCK_ZERO_DIR:
    case IDC_EDIT_RED_LIGHT_TIME:
    case IDC_EDIT_SEVER_TYPE:
    case IDC_EDIT_SINK_DIR:
    case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
    case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
    case IDC_EDIT_FUEL_TIME:
     case IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN:
     case IDC_EDIT_MAC_PARAM_SINK1:
     case IDC_EDIT_MAC_PARAM_SINK2:
	    {
	        OnCreateKeyboard(hWnd, nID);
	    }
	    break;
	}
}
/*
 *
 */
static void OnKeyDown(HWND hWnd, uint key)
{
	if(key == SCANCODE_ESCAPE)
	{
		OnBtnCmd(hWnd, ID_ESC);
	}
    else if(key == SCANCODE_CURSORBLOCKLEFT)
    {
        uint nID = 0;
        switch(GetDlgCtrlID(GetFocusChild(hWnd)))
        {
        case IDC_EDIT_SINK_DIR:
            nID = IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_YARN_TYPE:
            nID = IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_NULL_DATA:
            nID = IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN;
            break;
        }
        if(nID)
	    {
	        SetFocusChild(GetDlgItem(hWnd, nID));
	    }
    }
    else if(key == SCANCODE_CURSORBLOCKRIGHT)
    {
        uint nID = 0;
        switch(GetDlgCtrlID(GetFocusChild(hWnd)))
        {
        case IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_SINK_DIR;
            break;
        case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_YARN_TYPE;
            break;
        case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_FUEL_TIME:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_FUEL_GAB:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_ROCK_MODE:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_ROCK_ZERO_DIR:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_RED_LIGHT_TIME:
            nID = IDC_EDIT_NULL_DATA;
            break;
        case IDC_EDIT_SEVER_TYPE:
            nID = IDC_EDIT_NULL_DATA;
            break;
        }
        if(nID)
	    {
	        SetFocusChild(GetDlgItem(hWnd, nID));
	    }
    }
    else if(key == SCANCODE_CURSORBLOCKUP)
    {
        uint nID = 0;
        switch(GetDlgCtrlID(GetFocusChild(hWnd)))
        {
        case IDC_EDIT_SEVER_TYPE:
            nID = IDC_EDIT_RED_LIGHT_TIME;
            break;
        case IDC_EDIT_RED_LIGHT_TIME:
            nID = IDC_EDIT_ROCK_ZERO_DIR;
            break;
        case IDC_EDIT_ROCK_ZERO_DIR:
            nID = IDC_EDIT_ROCK_MODE;
            break;
        case IDC_EDIT_ROCK_MODE:
            nID = IDC_EDIT_FUEL_GAB;
            break;
        case IDC_EDIT_FUEL_GAB:
            nID = IDC_EDIT_FUEL_TIME;
            break;
        case IDC_EDIT_FUEL_TIME:
            nID = IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN;
            break;
        case IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN:
            nID = IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN;
            break;
        case IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN:
            nID = IDC_EDIT_MAC_WIDTH;
            break;
        case IDC_EDIT_MAC_WIDTH:
            nID = IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
            nID =  IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_NULL_DATA:
            nID = IDC_EDIT_YARN_TYPE;
            break;
        case IDC_EDIT_YARN_TYPE:
            nID = IDC_EDIT_SINK_DIR;
            break;
        default:
            break;
        }
        if(nID)
	    {
	        SetFocusChild(GetDlgItem(hWnd, nID));
	    }
    }
    else if(key == SCANCODE_CURSORBLOCKDOWN)
    {
        uint nID = 0;
        switch(GetDlgCtrlID(GetFocusChild(hWnd)))
        {
        case IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_DUMU2_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_DUMU3_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN;
            break;
        case IDC_EDIT_DUMU4_TO_MAC_LEFT_LEN:
            nID = IDC_EDIT_MAC_WIDTH;
            break;
        case IDC_EDIT_MAC_WIDTH:
            nID = IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN;
            break;
        case IDC_EDIT_SELECT5_TO_MAC_RIGHT_LEN:
            nID = IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN;
            break;
        case IDC_EDIT_SELECT6_TO_MAC_RIGHT_LEN:
            nID = IDC_EDIT_FUEL_TIME;
            break;
        case IDC_EDIT_FUEL_GAB:
            nID = IDC_EDIT_FUEL_TIME;
            break;
        case IDC_EDIT_FUEL_TIME:
            nID = IDC_EDIT_ROCK_MODE;
            break;
        case IDC_EDIT_ROCK_MODE:
            nID = IDC_EDIT_ROCK_ZERO_DIR;
            break;
        case IDC_EDIT_ROCK_ZERO_DIR:
            nID = IDC_EDIT_RED_LIGHT_TIME;
            break;
        case IDC_EDIT_RED_LIGHT_TIME:
            nID = IDC_EDIT_SEVER_TYPE;
            break;
        case IDC_EDIT_SINK_DIR:
            nID =  IDC_EDIT_YARN_TYPE;
            break;
        case IDC_EDIT_YARN_TYPE:
            nID = IDC_EDIT_NULL_DATA;
            break;
        default:
            break;
        }
        if(nID)
	    {
	        SetFocusChild(GetDlgItem(hWnd, nID));
	    }
    }
    else if(key == SCANCODE_ENTER)
    {
        ushort nID = GetDlgCtrlID(GetFocusChild(hWnd));
       OnBtnCmd(hWnd, nID);
    }
}
/*
 *
 */
static int MacParamWinProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
    {
    case MSG_CREATE:
        {
        	CreateMacParamInterface(hWnd);
        }
        break;
    case MSG_PAINT:
        {
            HDC hdc = GetClientDC(hWnd);
            RECT rect;
            GetClientRect(hWnd, &rect);
            rect.left += 200;
            rect.top += MASTER_TITLE_TOP;
            rect.right -= 200;
            rect.bottom = rect.top + MASTER_TITLE_HEIGHT - 1;
            SetBkMode(hdc, BM_TRANSPARENT);
            SetTextColor(hdc, COLOR_HQ_GREEN(hdc));
            DrawText(hdc, GetWindowCaption (hWnd), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
            ReleaseDC(hdc);
        }
        break;
    case MSG_CLOSE:
        {
            HWND hHosting = GetHosting(hWnd);
            if(hHosting != HWND_INVALID)
            {
                EnableWindow(hHosting, TRUE);
            }
            DestroyMainWindow(hWnd);
            MainWindowCleanup(hWnd);
        }
        return 0;
    case MSG_DESTROY:
        {
            ShowWindow(hWnd, SW_HIDE);
            DestroyAllControls(hWnd);
        }
        break;
    case MSG_KEYDOWN:
    	{
    	    OnKeyDown(hWnd, wParam);
    	    OnChangeCtrl(hWnd);
    	}
        return 0;
    case MSG_ERASEBKGND:
        {
           DrawBitmapBkGnd(hWnd, (RECT*)lParam, &g_bmp[BMP_WORK]);
        }
    	return 0;
    case MSG_COMMAND:
        {
            OnChangeCtrl(hWnd);
        	OnBtnCmd(hWnd, LOWORD(wParam));
        }
    	return 0;
    case MSG_SETDATA:
        OnSetKnitValue(hWnd, LOWORD(wParam));
        return 0;
    }
    return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
/*
 *
 */
HWND CreateMacParamWindow(HWND hHosting)
{
    int x = (CX_SCREEN - CX_XTCS_WND_BMP) / 2;
    int y = (CY_SCREEN - CY_XTCS_WND_BMP) / 2;
    MAINWINCREATE CreateInfo;
    CreateInfo.dwStyle = WS_VISIBLE;
    CreateInfo.dwExStyle = WS_EX_NONE;
    CreateInfo.spCaption = MW_SET_MAC_PARAM;
    CreateInfo.hMenu = 0;
    CreateInfo.hCursor = GetSystemCursor(0);
    CreateInfo.hIcon = 0;
    CreateInfo.MainWindowProc = MacParamWinProc;
    CreateInfo.lx = x;
    CreateInfo.ty = y;
    CreateInfo.rx = x + CX_XTCS_WND_BMP;
    CreateInfo.by = y + CY_XTCS_WND_BMP;
    CreateInfo.iBkColor = COLOR_lightwhite;
    CreateInfo.dwAddData = 0;
    CreateInfo.hHosting = hHosting;
    HWND hWnd = CreateMainWindow(&CreateInfo);
    if(hWnd != HWND_INVALID)
    {
        EnableWindow(hHosting, FALSE);
        SetFocusChild(GetDlgItem(hWnd, IDC_EDIT_DUMU1_TO_MAC_LEFT_LEN));
        ShowWindow(hWnd, SW_SHOWNORMAL);
    }
    return hWnd;
}
